package com.the;

import java.util.HashMap;
import java.util.Map;

public class MapPractice {
    public static void main(String[] args) {
        Map<String, String> data = new HashMap<>();
        data.put("小明", "A");
        data.put("小王", "B");
        data.put("小李", "A");
        data.put("小张", "D");
        data.put("小赵", "C");
        data.put("小孙", "C");
        data.put("小周", "A");
        data.put("小吴", "D");
        data.put("小郑", "B");
        data.put("天天", "D");
        data.put("王二", "A");
        data.put("李四", "B");
        data.put("李五", "C");
        data.put("赵六", "C");
        data.put("孙七", "D");
        data.put("钱八", "A");


    }
    public static void count(Map<String, String> data){
        //创建一个新的map集合统计投票，遍历，A——>value,判断存在的话，value+1，不存在的话，value=1
        Map<String, Integer> resultMap = new HashMap<>();
        data.forEach((k, v) -> {
            boolean containsKey = resultMap.containsKey(v);
            if (containsKey) {//存在在之前的值上加1
                Integer oldValue = resultMap.get(v);
                resultMap.put(v, oldValue + 1);
            } else {          //不存在，直接赋值1
                resultMap.put(v, 1);
            }
        });
        resultMap.forEach((k, v) -> System.out.println(k + "--->" + v));
    }
}
